<template>
  <view>
    <!-- 头部导航栏 -->
    <uv-navbar title="添加联系人" border left-icon="" placeholder></uv-navbar>
  </view>

  <view class="body-container">
    <!-- <uv-input type="text" placeholder="测试用"></uv-input> -->
    <uv-form :model="contact" :rules="rules" ref='form' label-width="130rpx">
      <uv-form-item label="姓名" prop="name" border-bottom>
        <!-- 重名问题暂未考虑 -->
        <uv-input v-model="contact.name" type="text" placeholder="请输入联系人姓名"></uv-input>
      </uv-form-item>
      <uv-form-item label="性别" prop="gender" border-bottom>
        <uv-radio-group v-model="contact.gender">
          <uv-radio name="M" label="男"></uv-radio>
          <uv-radio name="F" label="女"></uv-radio>
        </uv-radio-group>
      </uv-form-item>

      <uv-form-item label="手机号" prop="phone" border-bottom>
        <!-- // 看看是否能调整格式变成xxx-xxxx-xxxx，外国号码不考虑 -->
        <uv-input v-model="contact.phone" type="text" placeholder="输入手机号"></uv-input>
      </uv-form-item>
      <uv-form-item label="公司" prop="organization" border-bottom>
        <!-- 需要能选择 -->
        <uv-input v-model="contact.organization" placeholder="联系人就职公司"></uv-input>
      </uv-form-item>
      <uv-form-item label="其他信息" prop="otherInfo" border-bottom>
        <uv-textarea v-model="contact.otherInfo" type="text" placeholder="可记录爱好 兴趣 评价 风格等" height="500rpx"></uv-textarea>
      </uv-form-item>
    </uv-form>
  </view>

  <view>
    <!-- 底部 -->
    <bottomTab type='submit'></bottomTab>
  </view>
</template>

<script setup>
  import {
    ref
  } from 'vue';
  import nx from '@/nx';
  defineOptions({
    name: "addContact",
  })
  import {onLoad} from '@dcloudio/uni-app'
  const contact = ref({
    name: "",
    phone: '',
    // wechat:'',
    organization: '',
    orgId: '',
    gender: 'M',
    otherInfo: '',
    // bizcard:'',  //名片功能先不弄
  })
  const contactApi = nx.$api.contact
  const submit = async () => {
    let resp = await contactApi.addContact(contact.value)
    if (resp.code === 200){
      console.log(resp.data);
      uni.navigateBack(1)
    }
  }
  
  
  onLoad(() => {
    uni.$on('bottomTabSubmit', () => {
      submit()
    })
  })
</script>

<style lang="scss" scoped>
  .uv-radio {
    margin: 0 20rpx 0;
  }
</style>